﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/SystemManagers/SystemManagers.master"
    Inherits="System.Web.Mvc.ViewPage<Diploma.Models.SubOrderPractice>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%: Html.Resource("title_SubOrder")%>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="order">
        <div id="OrderMenu">
            <ul>
                <li><a href="<%:Url.RouteUrl("Default",
                                           new
                                               {
                                                   controller = "OrderPractice",
                                                   action = "Room",
                                                   orderId = Model.OrderPracticeId
                                               })%>"><%: Html.Resource("lbl_ToMainOrder")%></a></li>
                <%
                    if (Model.OrderStatu.Value == 2 && Model.OrderDiploms.Count == 0)
                    {%>
                <li><a href="<%:Url.RouteUrl("Default",
                                                       new
                                                           {
                                                               controller = "OrderDiplom",
                                                               action = "Create",
                                                               subPracticeOrderId = Model.Id
                                                           })%>"><%: Html.Resource("lbl_CreateOrderToDiplom")%></a></li>
                <%}
                    else if (Model.OrderDiploms != null && Model.OrderDiploms.Count > 0)
                    {%>
                <li><a href="<%: Url.RouteUrl("Default", new {controller="OrderDiplom", action="Room", orderId = Model.OrderDiploms.First().Id}) %>">
                    <%: Html.Resource("lbl_ToDiplomOrder")%></a></li>
                <%
                   }%>
            </ul>
        </div>
        <div class="order_body">
            <div id="order-info" class="order-div-head">
                <%: Html.Resource("lbl_AboutOrder")%>
            </div>
            <div id="order-info-div">
            </div>
            <div id="order-status" class="order-div-head">
                <%: Html.Resource("lbl_Status")%>
            </div>
            <div id="order-status-div">
            </div>
            <div id="order-document" class="order-div-head">
                <%: Html.Resource("lbl_Excel")%>
            </div>
            <div id="order-document-div">
            </div>
            <% if (Model.OrderStatu.Value > 0 && Model.OrderStatu.Value != 3) { %>
            <div id="order-upload" class="order-div-head">
                <%: Html.Resource("lbl_UploadFiles")%>
            </div>
            <div id="order-upload-div">
            </div>
            <% } %>
            <div id="order-student" class="order-div-head">
                <%: Html.Resource("lbl_ListOfStudents")%>
            </div>
            <div id="order-student-div">
            </div>
        </div>
        <div style="clear: both;">
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptsContent" runat="server">
    <script type="text/javascript">
        var orderId = '<%:Model.Id.ToString()%>';

        $(document).ready(function () {
            LoadStudentList();
            LoadInfo();
            LoadStatus();
            LoadExcelGeneration();
        });

        function LoadStudentList() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "SubOrderPractice", action = "StudentList"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-student-div").html(response);
                }
            });
        }

        function LoadInfo() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "SubOrderPractice", action = "GetInfo"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-info-div").html(response);
                }
            });
        }

        function LoadEditInfo() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "SubOrderPractice", action = "GetEditForm"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-info-div").html(response);
                    $("#StopDate").datepicker($.datepicker.regional['ru']);
                    $("#StartDate").datepicker($.datepicker.regional['ru']);
                }
            });
        }

        function SaveInfo() {
            var title = $("#Title").val();
            var text = $("#Text").val();
            var bookName = $("#BookName").val();
            var dateAndOrderNumber = $("#DateAndOrderNumber").val();

            var path = '<%:Url.RouteUrl("Default", new {controller = "SubOrderPractice", action = "SaveInfo"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId, title: title, text: text, bookName: bookName, dateAndOrderNumber: dateAndOrderNumber }),
                success: function (response) {
                    if (response) {
                        LoadInfo();
                    }
                }
            });
        }

        function LoadStatus() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "SubOrderPractice", action = "GetStatus"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-status-div").html(response);
                }
            });
        }

        function ChangeStatus() {
            var statusId = $("#OrderStatus option:selected").val();
            var path = '<%:Url.RouteUrl("Default", new {controller = "SubOrderPractice", action = "SaveStatus"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId, statusId: statusId }),
                success: function (response) {
                    LoadStatus();
                    window.location.reload();
                }
            });
        }

        function LoadExcelGeneration() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "SubOrderPractice", action = "ExcelViewPart"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-document-div").html(response);
                }
            });
        }
    </script>
    <%
        if (Model.OrderStatu.Value > 0 && Model.OrderStatu.Value != 3)
        {%>
    <script type="text/javascript">
        $(document).ready(function () {
            LoadUploadFiles();
        });

        function CreateSubOrderPractice() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "SubOrderPractice", action = "GenerateExcel"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    switch (response.type) {
                        case "create":
                            window.location = response.url;
                            break;
                        case "download":
                            window.location = response.url;
                            break;
                        default:
                            break;
                    }
                }
            });
        }

        function LoadUploadFiles() {
            var path = '<%:Url.RouteUrl("Default", new {controller = "SubOrderPractice", action = "UploadFilesView"})%>';
            $.ajax({
                url: path,
                type: "POST",
                async: false,
                data: ({ orderId: orderId }),
                success: function (response) {
                    $("#order-upload-div").html(response);
                }
            });
        }
    </script>
    <%
        }%>
</asp:Content>
